package com.baoteng.room.utils;

import android.arch.persistence.room.TypeConverter;
import android.text.TextUtils;

import com.baoteng.component.parser.GsonHelper;

import java.util.List;

/**
 * Author: loren
 * Date: 2019/8/12
 * <p>
 * 数据转换器
 */
public class Converters {
    @TypeConverter
    public static String strList2Str(List<String> strList) {
        if (strList == null || strList.isEmpty())
            return "";
        return GsonHelper.toJson(strList);
    }

    @TypeConverter
    public static List<String> str2StrList(String str) {
        if (TextUtils.isEmpty(str))
            return null;
        return GsonHelper.fromJsonToList(str, String[].class);
    }

}
